<%@ page language="java" session="true" errorPage="ElderhealthError.jsp"%>
<%@ page import="com.elderhealth.client.Client"%>
<%@ page import="com.elderhealth.worker.HomecareWorker"%>
<%@ page import="com.elderhealth.schedule.Appointment"%>
<%@ page import="com.elderhealth.util.DBManager"%>
<%
/*
 * Source:   GetClientSchedule.jsp
 * Purpose:  This page will display the schedule of the selected client
 */
%>

<html>
<head>
<link rel="stylesheet" type="text/css" href="elderhealth.css">
<!-- Scripting Portion -->
<script type="text/javascript" src="elderhealth.js"></script>
</head>
<body>

<%@ include file="ElderhealthHeader.jsp" %>

<%
/* Intialize variables */
String errorCode;
String errorMessage;
String redirectURL;
int clientID = 0;

try
{
  /* Retrieve client id from the passed parameters */
  int selectedClientID = Integer.parseInt(request.getParameter("clientID"));
  /* Retrieve clients and present them */
  Appointment [] clientAppointments = Appointment.getAppointmentsByClient(selectedClientID, null, null); 
  Appointment appointment = null;
  Client client = null;
%>  
<table border=0 align="left" border=0 cellpadding=0 cellspacing=0 width="600">
    <tr class="contactHeaderText"><td height="18" align="left" valign="middle" style="PADDING-LEFT:10px">View Client Appointments</td></tr>
    <tr><td class="layoutLine" valign="middle" align="left" width="302" height="1" colSpan="4"></td></tr>
    <tr class="contactBar1">
    <td align="left" valign="middle" style="PADDING-LEFT:10px">
<%
if (clientAppointments == null || clientAppointments.length == 0)
{
%>
    This client has no appointments<br>

<%
}
else
{
    HomecareWorker worker = null; 
    appointment = (Appointment) clientAppointments[0];
    client = (Client) appointment.getClient();
    out.println(client.getClientName() + " has a total of " + clientAppointments.length + " appointments:<br>");
    String outText = "";
    for (int iApp=0; iApp < clientAppointments.length; iApp++)
    {
        outText = "";
        appointment = (Appointment) clientAppointments[iApp];
        worker = (HomecareWorker) appointment.getWorker();
        outText = "<br><strong>(" + (iApp+1) + ")</strong>";
        outText += " with " + worker.getWorkerName() + " between ";
        outText += appointment.getStartTime().toString() + " and ";
        outText += appointment.getEndTime().toString() + " ";
        out.println (outText);
    }
    out.println ("<br>");
        
}
/* Check to make sure the clients from the search are still part of the session variable */
}
catch (Exception e) 
{
    errorCode = "1";
    errorMessage = "Error occurred in GetClientSchedule.jsp ." + clientID + " Error is:" +
                   e.toString();
    redirectURL = "ElderhealthError.jsp?errorCode=" + errorCode + "&errorMessage=" + errorMessage;
    response.sendRedirect(redirectURL);
}
%>
	<br>
    </td></tr>
    <tr><td class="layoutLine" valign="middle" align="left" width="302" height="1" colSpan="4"></td></tr>
</table>

</body>
</html>